/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package jcac_1_0.v.main;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import jcac_1_0.util.AppConf;
import jcac_1_0.util.ConnectionConfUtil;
import jcac_1_0.util.JFrameUtil;
import jcac_1_0.v.setting.FrmWorkTime;
import jcac_1_0.v.employee.FrmEmployeeList;
import jcac_1_0.v.reportexport.FrmMenjinReportExport;

/**
 *
 * @author SoChishun
 */
public class FrmMain extends javax.swing.JFrame {

    /**
     * Creates new form FrmMain
     */
    public FrmMain() {
        initComponents();
        this.setTitle(AppConf.APP_TITLE);
        this.setLocationRelativeTo(null); // 窗体居中对齐 2016-5-17
        // 关闭窗体确认对话框 2016-5-17
        this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                if (JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(null, "您确定要退出程序吗?")) {
                    System.exit(0);
                }
            }

        });
        // 菜单事件委托 2016-5-17
        jMenuItemAction();
        try {
            // 连接数据库
            ConnectionConfUtil.Read();
        } catch (IOException | SQLException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
        }
    }

    /**
     * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jmi_上班时间设置 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jmi_员工管理 = new javax.swing.JMenuItem();
        jmi_部门管理 = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jmi_导入打卡记录 = new javax.swing.JMenuItem();
        jmi_导入请假记录 = new javax.swing.JMenuItem();
        jmi_清空导入数据 = new javax.swing.JMenuItem();
        jMenu4 = new javax.swing.JMenu();
        jmi_导出门禁报表 = new javax.swing.JMenuItem();
        jmi_导出考勤登记报表 = new javax.swing.JMenuItem();
        jmi_导出考勤统计报表 = new javax.swing.JMenuItem();
        jMenu5 = new javax.swing.JMenu();
        jmi_关于 = new javax.swing.JMenuItem();
        jmi_检查更新 = new javax.swing.JMenuItem();
        jmi_打开安装目录 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("欢迎使用!");

        jMenu1.setMnemonic('S');
        jMenu1.setLabel("设置(S)");

        jmi_上班时间设置.setMnemonic('T');
        jmi_上班时间设置.setText("上班时间设置(T)");
        jMenu1.add(jmi_上班时间设置);

        jMenuBar1.add(jMenu1);

        jMenu2.setMnemonic('U');
        jMenu2.setText("用户(U)");

        jmi_员工管理.setMnemonic('E');
        jmi_员工管理.setText("员工管理(E)");
        jMenu2.add(jmi_员工管理);

        jmi_部门管理.setMnemonic('D');
        jmi_部门管理.setText("部门管理(D)");
        jMenu2.add(jmi_部门管理);

        jMenuBar1.add(jMenu2);

        jMenu3.setMnemonic('I');
        jMenu3.setText("导入(I)");

        jmi_导入打卡记录.setMnemonic('K');
        jmi_导入打卡记录.setText("导入打卡记录(K)");
        jMenu3.add(jmi_导入打卡记录);

        jmi_导入请假记录.setMnemonic('J');
        jmi_导入请假记录.setText("导入请假记录(J)");
        jMenu3.add(jmi_导入请假记录);

        jmi_清空导入数据.setMnemonic('Q');
        jmi_清空导入数据.setText("清空导入数据(Q)");
        jMenu3.add(jmi_清空导入数据);

        jMenuBar1.add(jMenu3);

        jMenu4.setMnemonic('E');
        jMenu4.setText("导出(E)");

        jmi_导出门禁报表.setMnemonic('M');
        jmi_导出门禁报表.setText("导出门禁报表(M)");
        jMenu4.add(jmi_导出门禁报表);

        jmi_导出考勤登记报表.setMnemonic('D');
        jmi_导出考勤登记报表.setText("导出考勤登记表(D)");
        jMenu4.add(jmi_导出考勤登记报表);

        jmi_导出考勤统计报表.setMnemonic('T');
        jmi_导出考勤统计报表.setText("导出考勤统计表(T)");
        jMenu4.add(jmi_导出考勤统计报表);

        jMenuBar1.add(jMenu4);

        jMenu5.setMnemonic('H');
        jMenu5.setText("帮助(H)");

        jmi_关于.setMnemonic('A');
        jmi_关于.setText("关于(A)");
        jMenu5.add(jmi_关于);

        jmi_检查更新.setMnemonic('U');
        jmi_检查更新.setText("检查更新(U)");
        jMenu5.add(jmi_检查更新);

        jmi_打开安装目录.setMnemonic('X');
        jmi_打开安装目录.setText("打开安装目录(X)");
        jMenu5.add(jmi_打开安装目录);

        jMenuBar1.add(jMenu5);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addContainerGap(700, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addContainerGap(385, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * 菜单点击事件处理
     *
     * @version 1.0 2016-5-17 SoChishun Added.
     */
    void jMenuItemAction() {
        jmi_上班时间设置.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JFrameUtil.openJFrame(FrmWorkTime.class);
            }
        });
        jmi_员工管理.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JFrameUtil.openJFrame(FrmEmployeeList.class);
            }
        });
        jmi_导出门禁报表.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JFrameUtil.openJFrame(FrmMenjinReportExport.class);
            }
        });
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrmMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrmMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrmMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrmMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FrmMain().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenu jMenu5;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jmi_上班时间设置;
    private javax.swing.JMenuItem jmi_关于;
    private javax.swing.JMenuItem jmi_员工管理;
    private javax.swing.JMenuItem jmi_导入打卡记录;
    private javax.swing.JMenuItem jmi_导入请假记录;
    private javax.swing.JMenuItem jmi_导出考勤登记报表;
    private javax.swing.JMenuItem jmi_导出考勤统计报表;
    private javax.swing.JMenuItem jmi_导出门禁报表;
    private javax.swing.JMenuItem jmi_打开安装目录;
    private javax.swing.JMenuItem jmi_检查更新;
    private javax.swing.JMenuItem jmi_清空导入数据;
    private javax.swing.JMenuItem jmi_部门管理;
    // End of variables declaration//GEN-END:variables
}
